package com.dc.mpg;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * mybatisplus代码生成器
 *
 * @author duchao
 */
public class CodeGenerator {

    public static void main(String[] args) {

        String projectPath = "/redis/springboot-redis";
        String packageName = "com.dc.dd";
        String[] tableArr = {"t_account"};
        String dbUrl = "182.92.202.68:8024/ds-account";
        String dbUserName = "root";
        String dbPwd = "duchao123";

        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)
                .setUrl("jdbc:mysql://" + dbUrl + "?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai")
                .setUsername(dbUserName)
                .setPassword(dbPwd)
                .setDriverName("com.mysql.cj.jdbc.Driver");

        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig
                .setCapitalMode(true)
                .setEntityLombokModel(true)
                .setNaming(NamingStrategy.underline_to_camel)
                .setInclude(tableArr)
                .setTablePrefix("t_");

        GlobalConfig config = new GlobalConfig();
        config.setActiveRecord(false)
                .setBaseResultMap(false)
                .setAuthor("duchao")
                .setOutputDir( System.getProperty("user.dir").replaceAll("\\\\","/").concat(projectPath).concat("/src/main/java/"))
                .setIdType(IdType.AUTO)
                .setFileOverride(true);

        new AutoGenerator().setGlobalConfig(config)
                .setDataSource(dataSourceConfig)
                .setStrategy(strategyConfig)
                .setPackageInfo(
                        new PackageConfig()
                                .setParent(packageName)
                                .setService("service")
                                .setServiceImpl("service.impl")
                                .setMapper("mapper")
                                .setXml("mapper.xml")
                                .setController("controller")
                                .setEntity("entity")).execute();
    }
}
